<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("title", "金豆充值");
%>
<%@ include file="/WEB-INF/views/shared/master/weContentHeader.jsp"%>
<style>
	.weui-cells{
		margin-top: 0px;
	}
	
	.rechargemoney>p{
		padding: 15px 10px;
		color: black;
		font-size: 16px;
	}
	.money{
		margin: 0px 10px;
		color: red;		
	}
	
	
	.color-blue {
		color: #2196F3;
	}
 	.bottom-btn {
		margin: 15px;
		padding: 2px;
		background-color: #2196F3;	
	} 
	
	.weui-btn_primary:not(.weui-btn_disabled):active{
		background-color: #2196F3;
	}
	
	.weui-btn_disabled{
	    background-color: #79c0f9 !important;
	    color:
	}
</style>

<%@ include file="/WEB-INF/views/shared/master/weTitle.jsp"%>


<div class="goback"
	data-back-href="<c:url value='/wechat/acc/myWealth/myWealth'/>"></div>
<div class="rechargemoney">
	<p>充值金额（元）</p>
	
	<div class="weui-cell">
		<div class="weui-cell__hd">
			<span style="font-size: 25px;color: black;font-weight: 500;padding-right: 10px">￥</span>
		</div>
		<div class="weui-cell__bd">
			<input class="weui-input selected-color" id="money" type="number" placeholder="充值建议100元以上" style="font-size: 18px;" onkeyup="btnColor(),checkMoney()">
		</div>
	</div>
	<span class="info" style="color: #ea693f;margin-left: 20px" hidden></span>
	<p>可用余额<span class="money"><fmt:formatNumber type="number" value="${accountInfo.balance}" maxFractionDigits="2"/></span>元</p>
</div>

<div style="width:100%;height:20px;background-color: #ebebeb;" >
  
</div>

 <div  style="z-index:500;">
	<a href="javascript:recharge();" data-href="<c:url value='/wechat/acc/myWealth/myWealth'/>" class="weui-btn weui-btn_primary bottom-btn recharge weui-btn_disabled" id="btn">充&nbsp;&nbsp;&nbsp;&nbsp;值</a>
</div>	 

<%@ include file="/WEB-INF/views/shared/scripts/jquery.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/jqweui.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/tabmob.jsp"%>

<%@ include file="/WEB-INF/views/shared/master/weContentFooter.jsp"%>

<script type="text/javascript">
   
   var $recharge = $(".recharge");
   var $money = $("#money");
   var value = '';
   //根据输入框是否有内容动态使按钮切换状态
   function btnColor(){
		 value =  $money.val();
		 if(value != ''){ 
			 if($recharge.attr("class").indexOf("weui-btn_disabled")>0){
				 $recharge.removeClass("weui-btn_disabled");
			 }
		 } 
		 if(value == ''||value ==0){ 
				 $("#btn").attr("disabled", true); 
				 $recharge.addClass("weui-btn_disabled");
		 } 
     } 
   
   /* 检查输入 */
	function checkInput() {
		if (checkMoney()) {
			return true;
		}
		return false;
	}
	/* 检查是否输入金额 */
	function checkMoney() {
		var money = $("#money").val();
		var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|131(^[0-9]\.[0-9]([0-9])?$)/;
		if (money == ''||money == 0) {
			$("#btn").attr("disabled", false);
			return false;
		}
		else if(!reg.test(money)){
			$("#btn").attr("disabled", true);
			$(".info").html("请输入正确的金额格式");
			$(".info").show();
			var $recharge = $(".recharge");
			$("#btn").attr("disabled", true); 
			$recharge.addClass("weui-btn_disabled");	
			/* $.toptip("请输入正确的金额","error"); */
			return false;
		}
		$(".info").hide();
		return true;
	}
      
      //点击充值按钮要执行的操作
       function recharge(){	
    	   if (!checkInput()) {
   			return;
   		}
    	 if(value != ''){
    		 var url=$.getVirtualPath()+"/wechat/acc/myWealth/toRecharge";
    	     $.post(url,{money:value},function(result){
    	    	 if(result == "true"){
    	    		 $.toast("充值成功");
    	    		 var href=$(".recharge").data("href");
    	    		 setTimeout(function() {
    	    			 window.location.href=href;
    	    		 }, 500);
    	    	 }else {
    	 			$.toast("充值失败", "forbidden");
    	 		}
    	     });
    	 }     
       } 
      
      
</script>





